package com.yz.mcd.view;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.text.Editable;
import android.text.TextWatcher;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;

import com.yz.mcd.BaseApplication;
import com.yz.mcd.R;
import com.yz.mcd.base.bcl.BaseBean;
import com.yz.mcd.base.imp.BaseActivityImp;
import com.yz.mcd.base.imp.BaseBeanImp;
import com.yz.mcd.bean.UserInfoBean;
import com.yz.mcd.model.UserInfoModel;

import butterknife.BindView;
import butterknife.ButterKnife;

public class Ac_login extends Activity implements BaseActivityImp {

    Button login_bn;
    TextView forget_tv;
    TextView register;
    EditText login_phone_et;
    EditText login_pw_et;
    UserInfoModel acUserInfoModel;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.layout_login);
        ButterKnife.bind(this);
        acUserInfoModel = new UserInfoModel(this);
        login_bn = (Button) findViewById(R.id.login_button);
        forget_tv = (TextView) findViewById(R.id.forgetpw_tv);
        register = (TextView) findViewById(R.id.register_tv);
        login_phone_et = (EditText) findViewById(R.id.login_phone_et);
        login_pw_et = (EditText) findViewById(R.id.login_pd_et);

        login_phone_et.setText("13929718507");
        login_pw_et.setText("123456");

        //EditText login_pd_et=(EditText)findViewById()
        login_bn.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                //Intent intent = new Intent(Ac_login.this,首页)
                UserInfoBean tmpBean = new UserInfoBean();
                if (getLoginUserInfoBean(tmpBean)) {
                    BaseApplication.cout(tmpBean.toString());
                    Log.e("TAG", tmpBean.toString());
                    BaseBean basemodelTemp = (BaseBean) tmpBean;
                    acUserInfoModel.handleInfo("Ac_log_1", basemodelTemp);
                }
            }
        });
        forget_tv.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent(Ac_login.this, Ac_findpw.class);
                startActivity(intent);
            }
        });
        register.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent(Ac_login.this, Ac_register.class);
                startActivity(intent);
            }
        });
        login_phone_et.addTextChangedListener(new TextWatcher() {
            @Override
            public void beforeTextChanged(CharSequence s, int start, int count, int after) {

            }

            @Override
            public void onTextChanged(CharSequence s, int start, int before, int count) {
                login_phone_et.setTextColor(0xFFFFFFFF);
            }

            @Override
            public void afterTextChanged(Editable s) {

            }
        });
        login_pw_et.addTextChangedListener(new TextWatcher() {
            @Override
            public void beforeTextChanged(CharSequence s, int start, int count, int after) {

            }

            @Override
            public void onTextChanged(CharSequence s, int start, int before, int count) {
                login_pw_et.setTextColor(0xFFFFFFFF);
            }

            @Override
            public void afterTextChanged(Editable s) {

            }
        });
    }

    public boolean getLoginUserInfoBean(UserInfoBean tmpBean) {
        String account, pw;
        account = login_phone_et.getText().toString();
        pw = login_pw_et.getText().toString();
        if (account.equals("") || pw.equals("")) {
            BaseApplication.cout(getString(R.string.info_no_full));
            return false;
        }
        tmpBean.setPhone(account);
        tmpBean.setUser_pwd(pw);
        return true;
    }

    public void infoChangeEvent(String type, BaseBeanImp bean) {

        switch (type) {
            case "Ac_log_1":
                BaseApplication.cout("XB");
                Log.e("TAG", BaseApplication.getUserInfo().getPhone());
                //添加跳转代码
                Intent intent = new Intent(Ac_login.this, Ac_main.class);
                startActivity(intent);//开始跳转
                finish();
                break;
            case "Ac_log_10":
                login_pw_et.setText("");
                break;
        }
    }
}
